Hello! Today, we're going to talk about a general
approach to chemical equilibrium and then some numerical methods that
are used to find the equilibrium state. So the approach we're going to talk
about is used in most computer codes. And you start again by
minimizing the Gibbs function, which you can write in
the general form as shown. And since P and T are constant, you have finally that the sum of
the chemical potentials times and change in number of moles have summed over
all the species has to be equal to zero. So this is a minimization
subject to a constraint in the constraint is
that atoms are conserved. In the previous video, we talked about a specific reaction and we wrote the story
kemetic equation for that reaction. But in general that we're going to have
an overall atoms conservation expression. So here Pk, which is the number
of k type atoms in the mixture is equal to the sum over
all of the types of atoms. j is the index, a is the total
number of types of atoms and sub kj is the number of k type
atoms in j-type molecules times the number of moles
of each j type molecule. So the equilibrium problem is
a minimization subject to a constraint. So we can go ahead and use the Lagrange's method of
undetermined multipliers for this. If we set dB k equal to zero and
multiply bu multipliers Lambda sub j and then add that to dG then
we get the next expression. And for that to be satisfied each term in
the in the bracket must be equal to zero. So that means that mu sub j minus
the sum over the Lambda sub k and some kj's has to be equal to zero. So for a perfect gas we can write mu as
a function of temperature and the partial pressure which is equal to the molar Gibbs
free energy at T in that partial pressure. That can be written as G at T and
P for the particular species plus the correction term the entropy
correction term pressure correction term. So we note that x is the partial pressure, we can write x is equal to
the exponent of the above expression and
plugging that into atom conservation, you get an expression for the pks. If you sum overall species you
get the bottom expression. So these provide a plus 1 equations for
the Lambda Ks and the end total. Now, of course,
you need thermodynamic data. You need to be able to
calculate the Gibbs function. And in all these programs thermodynamic
data are stored as polynomials. And this was first developed
at NASA by a woman named Bonnie McBride who was
the developer of the NASA equilibrium, original developer of
the NASA equilibrium code. And it's expressed in seven,
there are seven coefficients, A1 through A7. And so the expressions are used
to calculate the specific heat, the enthalpy and the entropy. And typically, the polynomials
are fit over to temperature ranges. This was all originally done for
as I mentioned for rocketry, as part of the anjana program and
military program. And so they were concerned
with temperatures running from 200 Kelvin up to 6000
Kelvin in some cases. And they discovered that if they split
that temperature range they could get a better fit. And so virtually, every code stores these as a double set of
polynomials and here's an example. This is the file format for Cantera,
but the other one look very similar. So in this case,
it gives the species name. It tells you how many atoms there are in
that species, so this is ethane c2h6. So there are 2 carbons and 6 hydrogen and then it does a NASA polynomial
fit from 300 to 1800 Kelvin and then again from 1800 to 3500 Kelvin. That's the range of
applicability of this data and you'll note that there
are 7 coefficients for each temperature range,
so 14 all together. And then below that is some data relating to transport
properties which we will get to later. In Cantera, they include the transport
data along with the thermodynamic data in a properties file. So here is a list of three three codes for
making equilibrium calculations. There are many more out there to our open
source and one is a commercial code, the NASA Lewis code was one of
the first that was developed. It was as I mentioned developed by Bonnie
McBride at NASA Lewis in Cleveland, Ohio. And it's free and you can download it, but it also comes with a gooey and so you
can do equilibrium calculations with it. One of the interesting things
is that it has an enormous thermodynamic properties
file with many many species. And if you don't know what you're likely
to encounter in the way of products, that can be very useful. Next is Cantera, Cantera is an open
source while the NASA Lewis code was written in Fortran by the way, and
you can download, installables. Cantera was written,
is a nuke newish code and it was originally started to be developed
by a professor Dave Goodwin at CALTECH and is written in C++, so
it's object oriented code. The third code that I want
to mention is CHEMKIN. CHEMKIN was originally
developed by Bob Kee and others at Sandia National Lab in Livermore as part of the activities of
the combustion research facility there. It was subsequently spun out to a startup
company named Reaction Design and a few years ago it was purchased by ANSA. So it's part of the ANSA's
suite of computational codes, I won't say anything more about it. It's expensive and it's not therefore
not available to most people. This is a screen view for
the NASA equilibrium code, chemical equilibrium with applications and you can either do calculations online or
you can download executables of the code called CA,
and I think the version is ca2. I'm not sure the menu on
the left gives you those choices. And then next here is a screenshot of
the opening page for Cantera. And so there's quite a bit of information on
here including installing and compiling. You can run Cantera relatively easily as a Python
application or a Matlab application and there are instructions in the installation
page for how to get it up and running. And there are tutorials,
there are examples, there's documentation on the various functions, and there is a page about the science of
what's behind the the code. So let's play around
a little bit with Cantera. You're seeing my computer screen and
my home page and I'll just type Cantera and Cantera dot-org pops
up because I look at this all the time. So I'm going to run Cantera in Python and we'll go to the installation page here. And I did a Conda installation
as described in this page. There are special Windows installations,
Mac installations and so on. But I did Conda and
they recommend the Conda, so you can install Conda. These are the various instructions for doing that, but
once you've installed it and I've already installed it obviously, the
way I run python is in a terminal window. So I'm going to click here on my
terminal window and get a new terminal. And then I have to activate Conda and I'm going to use this
command Conda activate spam and you can name your Conda
installation whatever you want. I just use the default spam. So I put that in my terminal window and
hit return and now you will see instead of the landline thing base, it says spam. This is what happens in Mac. Okay, so now what I'm going to do is open a file that contains a small Python script to run an equilibrium calculation. And this is the file here,
the commands in here. The first one imports Cantera, the second one imports numpy, numpy is a numerical methods
code that is used by Cantera. The next command sets the species and the species thermodynamic
properties of the gas that we're going to make
an equilibrium calculation on. And it actually in Python lingo creates
an object, cast one is the object, gri 30.xml, that is a file that contains the gas
research institute version 3.1 methane chemical reaction mechanism. And we'll go back and
look at this mechanism later, but suffice it to say that it
contains a list of species and their thermodynamic properties and we'll
see what those species are in a moment. The next command sets
the temperature pressure and composition, initial composition for
subsequent calculation. So I've got 2500 degrees Kelvin, one
atmosphere and this is Cantera notation. I can just,
instead of typing in the number, I can just type in C T
dot one underscore ATM. And then the initial composition
which is a stoichiometric mixture of methane oxygen and nitrogen. Next, I have to tell the code to
do an equilibration calculation. And so that's this next command
gas one dot equilibrate, and in the parentheses is TP and
single quotes that means this is a fixed temperature and
pressure calculation. And then by typing gas one
with close parentheses or empty parentheses that will
print out on the screen or in the terminal window the result. So to run this code, I have gone to
the directory where this code is and you see this prompt still says spam,
so I'm in Conda and so it will run Cantera. And now I just type my
Python version Python 3.7, and then ich will demo dot pi, and run it and there is the result. So here's the temperature and
pressure, 2500 Kelvin, one atmosphere in Pascal's, the density
that goes along with that temperature and pressure in the mean molecular weight. And the enthalpy internal energy
entropy gives function C sub p and C sub V and the mole fractions,
X mass and mass fractions and the chemical potential divided by
RT of all of the species except those that are below a certain
cutoff in concentration. And I think that cutoff is something like
10 to the minus 14, 10 to the minus 12. It's a big number I have to go in and
look. But species are small number, species whose mole fractions are less than
that or not included in the calculation. And so this is a list of
species that at 2500 Kelvin and 1 atmosphere exists in mole fraction large
enough not to be below that cut off. And I think the smallest mole fraction is about 1 times 10 to the 10
something like that. So that's an equilibrium calculation
demonstration using Cantera. So that's it for this video. Thanks for listening and have a great day.